package com.css.fxfzypg.modules.SettingSeismic.controller;

import com.css.fxfzypg.base.response.RestResponse;
import com.css.fxfzypg.logInfo.SysLog;
import com.css.fxfzypg.modules.SettingSeismic.entity.SettingSeismicFault;
import com.css.fxfzypg.modules.SettingSeismic.entity.SettingSeismicPoint;
import com.css.fxfzypg.modules.SettingSeismic.service.SettingSeismicService;
import com.css.fxfzypg.modules.hypergraph.service.HypergraphService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;

/**
 * @Description: fxfzypg
 * @Author: lhl
 * @CreateDate: 2022/10/13 16:22
 * 设定地震模块
 */
@RestController
@Validated
@RequestMapping("/settingSeismic")
public class SettingSeismicController {

    @Resource
    SettingSeismicService settingSeismicService;
    @Resource
    HypergraphService hypergraphService;

    @GetMapping("/all")
    public RestResponse getAll(@RequestParam String taskId){
        RestResponse restResponse=null;
        try {
            restResponse=settingSeismicService.getAll(taskId);
        }catch (Exception e){
            e.printStackTrace();
            restResponse=RestResponse.fail("查询失败!");
        }
        return restResponse;
    }

    @GetMapping("/getSpaceRange")
    public RestResponse getSpaceRange(@RequestParam String taskId){
        RestResponse restResponse=null;
        try {
            restResponse=settingSeismicService.getSpaceRange(taskId);
        }catch (Exception e){
            e.printStackTrace();
            restResponse=RestResponse.fail("查询失败!");
        }
        return restResponse;
    }

    @GetMapping("/getFault")
    public RestResponse getFault(@RequestParam String taskId){
        RestResponse restResponse=null;
        try {
            restResponse=settingSeismicService.getFault(taskId);
        }catch (Exception e){
            e.printStackTrace();
            restResponse=RestResponse.fail("查询失败!");
        }
        return restResponse;
    }

    @PostMapping("/saveSettingSeismicFault")
    public RestResponse saveSettingSeismicFault(@RequestBody SettingSeismicFault entity){
        RestResponse restResponse=null;
        try {
            restResponse=settingSeismicService.saveSettingSeismicFault(entity);
            //刷新指定超图工作空间数据源数据集
            boolean bool = hypergraphService.getWorkspaceReload("setting_seismic_point");

        }catch (Exception e){
            e.printStackTrace();
            restResponse=RestResponse.fail("保存失败!");
        }
        return restResponse;
    }

    @SysLog("点状设定地震")
    @PostMapping("/saveSettingSeismicPoint")
    public RestResponse saveSettingSeismicPoint(@RequestBody SettingSeismicPoint entity){
        RestResponse restResponse=null;
        try {
            entity.setFaultNum(null);
            restResponse=settingSeismicService.saveSettingSeismicPoint(entity);
            //刷新指定超图工作空间数据源数据集
            boolean bool = hypergraphService.getWorkspaceReload("setting_seismic_point");

        }catch (Exception e){
            e.printStackTrace();
            restResponse=RestResponse.fail("保存失败!");
        }
        return restResponse;
    }

    @PostMapping("/saveSettingSeismicPoint2")
    public RestResponse saveSettingSeismicPoint2(@RequestBody SettingSeismicPoint entity){
        RestResponse restResponse=null;
        try {
            entity.setFaultNum(null);
            //zyt--批量导入的经纬度保存点状设定地震
            restResponse=settingSeismicService.saveSettingSeismicPoint2(entity);
            //刷新指定超图工作空间数据源数据集
            boolean bool = hypergraphService.getWorkspaceReload("setting_seismic_point");

        }catch (Exception e){
            e.printStackTrace();
            restResponse=RestResponse.fail("保存失败!");
        }
        return restResponse;
    }

    @PostMapping("/importExcelPointLonLat")
    public RestResponse importExcel(MultipartFile file,String taskId) throws IOException {
        RestResponse restResponse = null;
        try {
            restResponse = settingSeismicService.importExcelPointLonLat(file,taskId);
        } catch (IOException e) {
            e.printStackTrace();
            restResponse = RestResponse.fail("导入失败!");
        }
        return restResponse;
    }


    @GetMapping("/getSettingSeismicPointById")
    public RestResponse getSettingSeismicPointById(@RequestParam String id){
        RestResponse restResponse=null;
        try {
            restResponse=settingSeismicService.getSettingSeismicPointById(id);
        }catch (Exception e){
            e.printStackTrace();
            restResponse=RestResponse.fail("查询失败!");
        }
        return restResponse;
    }

    @GetMapping("/getSettingSeismicDetailsById")
    public RestResponse getSettingSeismicDetailsById(@RequestParam String id){
        RestResponse restResponse=null;
        try {
            restResponse=settingSeismicService.getSettingSeismicDetailsById(id);
        }catch (Exception e){
            e.printStackTrace();
            restResponse=RestResponse.fail("查询失败!");
        }
        return restResponse;
    }

    @PostMapping("/updateSettingSeismicPoint")
    public RestResponse updateSettingSeismicPoint(@RequestBody SettingSeismicPoint entity){
        RestResponse restResponse=null;
        try {
            restResponse=settingSeismicService.updateSettingSeismicPoint(entity);
            //刷新指定超图工作空间数据源数据集
            boolean bool = hypergraphService.getWorkspaceReload("setting_seismic_point");

        }catch (Exception e){
            e.printStackTrace();
            restResponse=RestResponse.fail("修改失败!");
        }
        return restResponse;
    }


    @PostMapping("/deleteSettingSeismicFault")
    public RestResponse deleteSettingSeismicFault(@RequestParam String sfId){
        RestResponse restResponse=null;
        try {
            restResponse=settingSeismicService.deleteSettingSeismicFault(sfId,0);
            //刷新指定超图工作空间数据源数据集
            boolean bool = hypergraphService.getWorkspaceReload("setting_seismic_point");

        }catch (Exception e){
            e.printStackTrace();
            restResponse=RestResponse.fail("删除失败!");
        }
        return restResponse;
    }

    @SysLog("删除点状设定地震")
    @PostMapping("/deleteSettingSeismicPoint")
    public RestResponse deleteSettingSeismicPoint(@RequestParam String ssId){
        RestResponse restResponse=null;
        try {
            restResponse=settingSeismicService.deleteSettingSeismicPoint(ssId,0,null);
            //刷新指定超图工作空间数据源数据集
            boolean bool = hypergraphService.getWorkspaceReload("setting_seismic_point");

        }catch (Exception e){
            e.printStackTrace();
            restResponse=RestResponse.fail("删除失败!");
        }
        return restResponse;
    }
}
